public class BinarySearchTest {

  public static void main(String[] args) {
    int[] array = { 1, 2, 3, 5, 9, 10};
    System.out.println(binarySearch(array, 9, 0, array.length - 1));
  }

  private static int binarySearch(int[] array, int value, int left, int right) {

    if (left > right) return -1;

    int middle = (left + right) / 2;

    if (array[middle] == value) {
      return middle;
    } else if (array[middle] > value) {
      return binarySearch(array, value, left, middle - 1);
    } else {
      return binarySearch(array, value, middle + 1, right);
    }
  }
}
